package com.me.shop.user.service;

import org.springframework.transaction.annotation.Transactional;

import com.me.shop.user.bean.User;
import com.me.shop.user.dao.UserDao;
import com.me.shop.utils.MailUtils;
import com.me.shop.utils.UUIDUtils;

@Transactional
public class UserService {
	
	
	public UserDao userDao;
	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}
	
	public User findByUsername(String username) {
		return userDao.findByUsername(username);
	}

	public void save(User user) {
		user.setState(0); //0代表还没有激活， 1代表已激活
		String code = UUIDUtils.getUUID() + UUIDUtils.getUUID();
		user.setCode(code);
		userDao.save(user);
		MailUtils.send(user.getEmail(), code);
	}

	public User findbyCode(String code) {
		return userDao.findByCode(code);
	}

	public void update(User existUser) {
		userDao.update(existUser);
		
	}

	public User login(User user) {
		// TODO Auto-generated method stub
		return userDao.login(user);
	}
	
}
